import store from '../store'


/** 全局注册*/
export default {
  /**
   * 当被绑定元素插入到DOM时
   */
  inserted(el, binding, vnode) {
    const {value} = binding
    const all_permission = "*_*:*";
    const permissions = store.getters && store.getters.permissions

    if (value && value instanceof Array && value.length > 0) {
      const permissionFlag = value
      const hasPerm = permissions.some(permission => {
        return all_permission === permission || permissionFlag.includes(permission)
      })

      if (!hasPerm) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error(`请设置操作权限标签值`)
    }
  }

}

